-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for % in rgb and fix parsing for % in alpha. #2540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Hi! I was wondering if this could be merged or if I need to change anything/add more tests to it? |
| ctx.fillStyle = 'rgb( 100%, 99%, 80% 50%)' | ||
| assert.equal('rgba(255, 253, 204, 0.50)', ctx.fillStyle) | ||
|
|
||
| ctx.fillStyle = 'rgb( 100%, 99.99%, 40% / 50%)' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To my knowledge, this syntax is not supported in CSS or browsers and requires wrapping with calc().
Or use spaces to separate them:
rgb( 100% 99.99% 40% / 50% )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To my understanding, the slash here is to separate the rgb from alpha. According to CSS specifications the commas are legacy format, but there is no mention of it being unsupported or deprecated.
https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Values/color_value/rgb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked the MDN for color syntax, and yeah this makes sense. You cannot mix commas and / in the color property, however this was already the case in node-canvas, I just added a test for this.
@zbjornson @chearon is this something that should be fixed by adding formal syntax validation to rgb (and eventually other type) parsing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better not to, but it's probably not a big deal to parse the commas with the slash, since users will almost for sure be using one of the two syntaxes. Good to point it out though.

The parsing for % values in alpha wasn't working properly for single digit integers and for all decimal percentages starting with 0. Also added support for % parsing in rgb and rgba. This was mentioned in issue #1391 too.